package com.group01.web.controller;

import com.group01.annotation.Order;
import com.group01.dto.Order.OrderDeliveryDTO;
import com.group01.enums.CodeAndMessageEnum;
import com.group01.result.OrderPageTemplate;
import com.group01.result.Result;
import com.group01.service.OrderService;
import com.group01.vo.Order.OrderGetInfoVO;
import com.group01.vo.Order.OrderGetPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotEmpty;

/**
 * 订单模块
 * @Description
 * @Author 翟玉龙
 * @Date 2024/6/22
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单模块")
@Validated
public class OrderController {

    /**
     * 注入 订单模块 服务
     */
    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 分页 + 条件查询订单信息
     * @param pageNum 页码
     * @param pageSize 每页显示条数
     * @param id 订单编号
     * @param status 订单状态
     * @return {@link Result }<{@link OrderPageTemplate }<{@link OrderGetPageVO }>>
     */
    @ApiOperation("分页 + 条件查询订单信息")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result<OrderPageTemplate<OrderGetPageVO>> getOrderList(
            @PathVariable @DecimalMin(value = "1", message = "页码必须是数字且大于1") Integer pageNum,
            @PathVariable @DecimalMin(value = "1", message = "显示条数必须是数字且大于1") Integer pageSize,
            @RequestParam(value = "id" , required = false) String id,
            @RequestParam(value = "status" , required = false) @Order Integer status
    ) {
        return Result.success(CodeAndMessageEnum.FIND_RESULT,orderService.getOrderList(pageNum, pageSize, id, status));
    }

    /**
     * 根据订单编号查询订单信息
     * @param orderId 订单编号
     * @return {@link Result }<{@link OrderGetInfoVO }>
     */
    @ApiOperation("根据订单编号查询订单信息")
    @GetMapping("/{orderId}")
    public Result<OrderGetInfoVO> getOrderById(@PathVariable("orderId") @NotEmpty(message = "订单编号不能为空") String orderId){
        return Result.success(CodeAndMessageEnum.FIND_RESULT,orderService.getOrderInfoById(orderId));
    }

    /**
     * 填写发货信息
     * @param orderDeliveryDTO 订单配送信息DTO
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("填写发货信息")
    @PutMapping("/delivery")
    public Result<String> deliveryOrder(@RequestBody OrderDeliveryDTO orderDeliveryDTO){
        return orderService.deliveryOrderInfo(orderDeliveryDTO);
    }
}
